home *** CD-ROM | disk | FTP | other *** search
/ The X-Philes (2nd Revision) / The X-Philes Number 1 (1995).iso / xphiles / hp48hor1 / mulmod.doc < prev    next >
Text File  |  1995-03-31  |  2KB  |  47 lines

  1. Item: 768 by jurjen at cwi.nl 
  2. Author: [Jurjen NE Bos] 
  3.   Subj: Modulo computations on 48SX 
  4.   Keyw: Number theory 
  5.   Date: Tue Sep 18 1990 16:46  
  6.  Lines: 45 
  7.  
  8. This article is meant for factorization and number theory freaks. 
  9. I wrote a machine code program that does modulo multiplication for 
  10. binaries.  The program is equivalent to the RPL 
  11. \<< ROT ROT * SWAP DUP2 / * - \>>, 
  12. except that the latter program only works if the intermediate product is 
  13. smaller than 2^64. 
  14. This machine code version does not have this problem. 
  15.  
  16. Usage: 
  17. enter #a #b #m MULMOD to get (#a*#b) MOD #m 
  18. All arguments must be binaries. 
  19. #a must be < #m to make sure that the result is < #m. 
  20. #b and #m are unrestricted. 
  21. All arguments are checked, so that you don't have to be afraid for 
  22. mistakes.  You'll get a nice "Too Few Arguments" or "Bad Argument Type" 
  23. if applicable. 
  24.  
  25. Remark: it is only tested on a version D. 
  26. If you have another version, you're probably safe.  To be sure, check 
  27. out memory location 53F8D.  It should contain 174E773DF1C4143 for the 
  28. program to work. 
  29.  
  30. A nice example of the use of MULMOD is the "Random imitator". 
  31. The random generator uses internally a seed of 15 digits, and can be 
  32. imitated using the program: 
  33. \<< #2851130928467d R #1000000000000000 MULMOD DUP 'R' STO B->R 1E15 / 
  34. \>> 
  35. Seed the random generator by replacing 
  36.       .xxxxxxxxxxxxEyy RDZ 
  37. by 
  38.       #xxxxxxxxxxxxyy1 'R' STO 
  39. You can also produce the reverse of the random sequence replacing 
  40. the factor 2851130928467 by 953992389123803. 
  41. Have fun! 
  42. -- 
  43. |                 | "Never imagine yourself not to be otherwise than what | 
  44. | Jurjen N.E. Bos | it might appear to others that what you were or might | 
  45. |                 | have been was not otherwise than what you had been    | 
  46. |  jurjen@cwi.nl  | would have appeared to them to be otherwise."         | 
  47.